package com.lejin.order.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lejin.item.entity.CourseOutline;
import com.lejin.order.entity.OrderInfo;
import com.lejin.order.entity.OrderPay;
import com.lejin.order.mapper.CourseInfoMapper;
import com.lejin.order.mapper.CourseOrderConfirmMapper;
import com.lejin.order.service.ICourseOrderConfirmService;
import com.lejin.order.util.IdWorker;
import com.lejin.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class CourseOrderConfirmServiceImpl extends ServiceImpl<CourseOrderConfirmMapper, OrderInfo> implements ICourseOrderConfirmService {
    @Autowired
    private CourseInfoMapper courseInfoMapper;
    @Autowired
    private IdWorker idWorker;
    @Autowired
    private CourseOrderConfirmMapper courseOrderConfirmMapper;
    @Override
    public ResultVO addOrderInfo(CourseOutline courseOutline) {
        System.out.println(courseOutline);
        CourseOutline course = courseInfoMapper.selectById(courseOutline.getOutlineId());
        long Id = idWorker.nextId();
        System.out.println(Id);
        Date date = new Date();
        OrderInfo orderInfo = new OrderInfo();
        System.out.println("C"+date.toString()+ RandomUtil.randomNumbers(4));
        orderInfo.setOrderCreatetime(new Date());
        orderInfo.setOrderNumber("C"+Id);
        orderInfo.setCourseName(course.getOutlineName());
        orderInfo.setPricePaid(course.getPrice());
        orderInfo.setOrderStatus(1);

        int insert = courseOrderConfirmMapper.insert(orderInfo);
        return new ResultVO(true,"生成订单成功",orderInfo);


    }

//    @Override
//    public int updateOrderStatus(String orderId) {
////        UpdateWrapper updateWrapper = new UpdateWrapper();
////        int i = courseOrderConfirmMapper.updateById()
//          return 0;
//    }
}
